package com.store.framework.db;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.sql.rowset.CachedRowSet;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.store.framework.dao.IAppSchoolDao;
import com.store.framework.entry.AppSchoolTbl;

public class AppSchoolDao implements IAppSchoolDao {
	private static Log LOG = LogFactory.getLog(AppRootMapDao.class);

	@Override
	public int add(AppSchoolTbl d) {
		int b=0;
		String sql ="insert into app_school_tbl(Id,PerId,SDegree,"
				+ "SName,SBegDate,SEndDate,SClass,SAddDate,SaddPer,"
				+ "EditDate,EditPer,DelDate,DelPer,Del,Remarks) "
				+ "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		try {
			DaoUtil.executeUpdate(sql, d.getId(),d.getPerId(),
					d.getSdegree(),d.getSname(),d.getBegDate(),
					d.getEndDate(),d.getSclass(),d.getAddDate(),
					d.getAddPer(),d.getEditDate(),d.getEditPer(),
					d.getDelDate(),d.getDelPer(),d.getDel(),d.getRemarks());
			b=1;
		} catch (SQLException e) {
			b=0;
			LOG.error(e.getMessage(),e);
			throw new RuntimeException(e.getMessage(),e);
		}
		return b;
	}

	@Override
	public List<AppSchoolTbl> select() {
		List<AppSchoolTbl> list =new ArrayList<AppSchoolTbl>();
		String sql="select *from app_school_tbl";
		AppSchoolTbl appschooltbl =new AppSchoolTbl();
		try {
			CachedRowSet cs= DaoUtil.SimpleQuery(sql);
			while(cs.next()){
				appschooltbl.setId(cs.getString("Id"));
				appschooltbl.setPerId(cs.getString("PerId"));
				appschooltbl.setSdegree(cs.getString("SDegree"));
				appschooltbl.setSname(cs.getString("SName"));
				appschooltbl.setBegDate(cs.getLong("SBegDate"));
				appschooltbl.setEndDate(cs.getLong("SEndDate"));
				appschooltbl.setSclass(cs.getString("SClass"));
				appschooltbl.setAddDate(cs.getLong("SAddDate"));
				appschooltbl.setAddPer(cs.getString("SaddPer"));
				appschooltbl.setEditDate(cs.getLong("EditDate"));
				appschooltbl.setEditPer(cs.getString("EditPer"));
				appschooltbl.setDelDate(cs.getLong("DelDate"));
				appschooltbl.setDelPer(cs.getString("DelPer"));
				appschooltbl.setDel(cs.getLong("Del"));
				appschooltbl.setRemarks(cs.getString("Remarks"));
				list.add(appschooltbl);
			}
		} catch (SQLException e) {
			list =null;
			LOG.error(e.getMessage(),e);
			throw new RuntimeException(e.getMessage(),e);
		}
		return list;
	}

}
